/*
 * File:        hal_frame.h
 * Author:      buquan_chen
 * Comments:    the new framework
 * Data:        2024/12/13
 * Revision history: V0.1
 */
#ifndef _HAL_FRAME_H
#define _HAL_FRAME_H

#include "stdio.h"


//=================================================================================//
//                        Protocol configuration                   				   //
//Description:                                			   						   //
// 	1.Environment Definition(HAL_FRAME_ENVIRONMENT):                			   //
// 		1)0: Normal environment, 51, wch, etc;                                     //
// 		2)1: Use JL chip;                                    	   				   //
//=================================================================================//

#define HAL_FRAME_ENVIRONMENT 0

//=================================================================================//
#if HAL_FRAME_ENVIRONMENT
#include "syscfg_id.h"	//Use the available IDs
#include "user_cfg_id.h"

#define CUSTOM_MODE_SIZE	1024
#define CUSTOM_MODE_NUM		3

#define mode1	48
#define mode2   48
#define mode3   49
#define mode4   49
#define mode5   50
#define mode6   50

void mode_data_init();

#else
#define custom_mode_based_adress	0
#define custom_mode1_adress 		custom_mode_based_adress
#define custom_mode2_adress    		custom_mode_based_adress + 512  
#define custom_mode3_adress 		custom_mode_based_adress + 512*2
#define custom_mode4_adress 		custom_mode_based_adress + 512*3
#define custom_mode5_adress 		custom_mode_based_adress + 512*4
#define custom_mode6_adress 		custom_mode_based_adress + 512*5

#endif

#define LEVEL_MASK         0xC0           // Loop level mask
#define END_MASK           0X20           // End of frame mask
#define ACTION_FRAME_TYPE  1              // Action frame
#define CYCLE_FRAME_TYPE   2              // Cycle frame
#define END_FRAME_TYPE     3              // End frame
#define CYCLE01_FRAME_TYPE 0x40         // 1st level cycle
#define CYCLE02_FRAME_TYPE 0x80 		// 2nd level cycle
#define CYCLE03_FRAME_TYPE 0xC0 		// 3rd level cycle

#define CYCLE_OVER_TYPE 0x0F 		//cycle address number exceeds 255

#define XXXX_TYPE  0x0F     //some action setting

struct custom_step_type {
    uint8_t action_set_H; // High byte of action settings锛�0x1F锛�
    uint8_t action_set_L; // Low byte of action settings锛�0xFF锛�
    uint8_t time;         // Time duration for the action
};
struct custom_frame{
	uint8_t  level;	
	uint8_t  next_address;
	uint8_t  cycle_times;	
};

union frame_type{
	uint8_t _data[3];
	struct custom_step_type action_frame;
	struct custom_frame	    fun_frame;
};

struct custom_action_type{
	uint8_t level0_times;
	uint8_t level1_times;
	uint8_t level2_times;
	uint8_t level3_times;	

	uint8_t action_id;
	uint16_t nxt_address;
	union frame_type frame;
};

uint16_t get_ation(void);
void set_action(uint8_t id);
void custom_action_init(void);
void Hal_frame_analy_recv(uint8_t *pValue, uint16_t len);
void Hal_frame_protocol_analy(uint8_t *buf,uint16_t len);
#endif
